package com.gaswell.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaswell.common.log.LogAnnotation;
import com.gaswell.entity.Qba01;
import com.gaswell.pojo.AlarmRecord;
import com.gaswell.service.AlarmRecordService;
import com.gaswell.service.UserService;
import com.gaswell.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/alarmRecord")
@Api(tags = "报警记录")
public class AlarmRecordController {
    @Autowired
    private AlarmRecordService alarmRecordService;
    @Autowired
    private UserService userService;

    @PostMapping("selectAll")
    @ApiOperation("查询所有数据")
    @LogAnnotation(module = "报警记录", operator = "查询所有数据")
    public Result selectAll(String userName) {
        int department = userService.selectUserByuserName(userName).getUser_department_id();
        return alarmRecordService.selectAll(department);
    }


    @PostMapping("selectAllByPage")
    @ApiOperation("分页查询所有数据   1 正序 0 倒序")
    @LogAnnotation(module = "报警记录", operator = "分页查询所有数据")
    public Result selectAllByPage(String userName, int current, int size, int sort) {
        int department = userService.selectUserByuserName(userName).getUser_department_id();
        Page<AlarmRecord> page = new Page<>(current, size);
        return alarmRecordService.selectAllByPage(page, department, sort);
    }


    @PostMapping("selectAllByPageAndJhAndCategory")
    @ApiOperation("根据井号和类别分页查询所有数据   1 正序 0 倒序")
    @LogAnnotation(module = "报警记录", operator = "根据井号和类别分页查询所有数据")
    public Result selectAllByPageAndJhAndCategory(String userName, int current, int size, int sort, String jh, String category, String start, String end) {
        int department = userService.selectUserByuserName(userName).getUser_department_id();
        Page<AlarmRecord> page = new Page<>(current, size);
        return alarmRecordService.selectAllByPageAndJhAndCategoryAndTime(page, department, sort, jh, category, start, end);
    }

    @PostMapping("updateOne")
    @ApiOperation("更新数据")
    @LogAnnotation(module = "报警记录", operator = "查询所有数据")
    public Result updateOne(String userName, @RequestBody AlarmRecord alarmRecord) {
        return alarmRecordService.updateOne(alarmRecord);
    }
}
